package com.example.wangfanwangluo.wangfanboss;

import android.content.Context;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.bigkoo.alertview.AlertView;
import com.bigkoo.alertview.OnItemClickListener;

public class KaidanActivity extends AppCompatActivity {


    final String[] userAddress = {"发货人地址","收货人地址"};
    final String[] titles = {"添加一条货物信息","包装","重量","体积"};
    final String[] service = {"货物价值","保险金额"};
    final String[] cost = {"到付","返款","欠返","回单份数","回单付","备注"};

    ListView fahuoNameListView;
    ListView fahuoPhoneListView;
    ListView shouhuoNameListView;
    ListView shouhuoPhoneListView;
    ListView goodsName1ListView;
    ListView goodsName2ListView;
    ListView goodsName3ListView;
    ListView goodsPackage1ListView;
    ListView goodsPackage2ListView;
    ListView goodsPackage3ListView;

    EditText fahuoName;
    EditText fahuoPhone;
    EditText shouhuoName;
    EditText shouhuoPhone;
    EditText goodsName1;
    EditText goodsName2;
    EditText goodsName3;
    EditText goodsPackage1;
    EditText goodsPackage2;
    EditText goodsPackage3;

    boolean zhuanxian = false;
    boolean qishi = false;
    boolean mudi = false;
    int sendNum = 0;
    int receiveNum = 0;
    int addNum = 0;
    int packageNum = 0;
    int weightNum = 0;
    int volumNum = 0;
    int huowujiazhi = 0;
    int baoxianjine = 0;
    int daofu = 0;
    int fankuan = 0;
    int qianfan = 0;
    int huidanfenshu = 0;
    int huidanfu = 0;
    int beizhu = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_kaidan);

        getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        ActionBar actionbar = getSupportActionBar();
        if (actionbar != null){
            actionbar.hide();
        }


        getEditTextFocus();

        initAction();

        backAction();

        getHistoryListView();
    }


    private void initAction() {

        TextView gengduo1 = (TextView)findViewById(R.id.kaidan_gengduo_1);
        gengduo1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                new AlertView.Builder().setContext(KaidanActivity.this)
                        .setStyle(AlertView.Style.ActionSheet)
                        .setTitle(null)
                        .setMessage(null)
                        .setCancelText("取消")
                        .setDestructive()
                        .setOthers(userAddress)
                        .setOnItemClickListener(new OnItemClickListener() {
                            @Override
                            public void onItemClick(Object o, int position) {
                                if (position >= 0) {
                                    addUserInfoAction(position);
                                }
                            }
                        })
                        .build()
                        .show();

            }
        });


        TextView gengduo2 = (TextView)findViewById(R.id.kaidan_gengduo_2);

        gengduo2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                new AlertView.Builder().setContext(KaidanActivity.this)
                        .setStyle(AlertView.Style.ActionSheet)
                        .setTitle(null)
                        .setMessage(null)
                        .setCancelText("取消")
                        .setDestructive()
                        .setOthers(titles)
                        .setOnItemClickListener(new OnItemClickListener() {
                            @Override
                            public void onItemClick(Object o, int position) {
                                if (position >= 0) {
                                    addGoodsInfoAction(position);
                                }
                            }
                        })
                        .build()
                        .show();

            }
        });


        TextView gengduo3 = (TextView)findViewById(R.id.kaidan_gengduo_3);

        gengduo3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                new AlertView.Builder().setContext(KaidanActivity.this)
                        .setStyle(AlertView.Style.ActionSheet)
                        .setTitle(null)
                        .setMessage(null)
                        .setCancelText("取消")
                        .setDestructive()
                        .setOthers(service)
                        .setOnItemClickListener(new OnItemClickListener() {
                            @Override
                            public void onItemClick(Object o, int position) {
                                if (position >= 0) {
                                    addServiceAction(position);
                                }
                            }
                        })
                        .build()
                        .show();

            }
        });

        TextView gengduo4 = (TextView)findViewById(R.id.kaidan_gengduo_4);

        gengduo4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                new AlertView.Builder().setContext(KaidanActivity.this)
                        .setStyle(AlertView.Style.ActionSheet)
                        .setTitle(null)
                        .setMessage(null)
                        .setCancelText("取消")
                        .setDestructive()
                        .setOthers(cost)
                        .setOnItemClickListener(new OnItemClickListener() {
                            @Override
                            public void onItemClick(Object o, int position) {
                                if (position >= 0) {
                                    addCostAction(position);
                                }
                            }
                        })
                        .build()
                        .show();

            }
        });


        final RelativeLayout zhuanxianAction = (RelativeLayout)findViewById(R.id.kaidan_zhuanxian);
        final RelativeLayout zhuanxianView = (RelativeLayout)findViewById(R.id.kaidan_layout_zhuanxian);

        final RelativeLayout qishiAction = (RelativeLayout)findViewById(R.id.kaidan_qishi);
        final RelativeLayout qishiView = (RelativeLayout)findViewById(R.id.kaidan_layout_qishi);

        final RelativeLayout mudiAction = (RelativeLayout)findViewById(R.id.kaidan_mudi);
        final RelativeLayout mudiView = (RelativeLayout)findViewById(R.id.kaidan_layout_mudi);
        zhuanxianAction.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (zhuanxian) {
                    zhuanxianView.setVisibility(View.GONE);
                }else {
                    zhuanxianView.setVisibility(View.VISIBLE);
                    qishiView.setVisibility(View.GONE);
                    mudiView.setVisibility(View.GONE);
                }
                zhuanxian = !zhuanxian;
            }
        });

        qishiAction.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (qishi) {
                    qishiView.setVisibility(View.GONE);
                }else {
                    qishiView.setVisibility(View.VISIBLE);
                    mudiView.setVisibility(View.GONE);
                    zhuanxianView.setVisibility(View.GONE);
                }
                qishi = !qishi;
            }
        });

        mudiAction.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mudi) {
                    mudiView.setVisibility(View.GONE);
                }else {
                    mudiView.setVisibility(View.VISIBLE);
                    zhuanxianView.setVisibility(View.GONE);
                    qishiView.setVisibility(View.GONE);
                }
                mudi = !mudi;
            }
        });


        TextView qishiSubmitAction = (TextView)findViewById(R.id.kaidan_queding_qishi);
        TextView qishiCancelAction = (TextView)findViewById(R.id.kaidan_quxiao_qishi);
        TextView mudiSubmitAction = (TextView)findViewById(R.id.kaidan_queding_mudi);
        TextView mudiCancelAction = (TextView)findViewById(R.id.kaidan_quxiao_mudi);


        qishiSubmitAction.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (qishi) {
                    qishiView.setVisibility(View.GONE);
                }else {
                    qishiView.setVisibility(View.VISIBLE);
                    mudiView.setVisibility(View.GONE);
                    zhuanxianView.setVisibility(View.GONE);
                }
                qishi = !qishi;
            }
        });

        mudiSubmitAction.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mudi) {
                    mudiView.setVisibility(View.GONE);
                }else {
                    mudiView.setVisibility(View.VISIBLE);
                    zhuanxianView.setVisibility(View.GONE);
                    qishiView.setVisibility(View.GONE);
                }
                mudi = !mudi;
            }
        });

        qishiCancelAction.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (qishi) {
                    qishiView.setVisibility(View.GONE);
                }else {
                    qishiView.setVisibility(View.VISIBLE);
                    mudiView.setVisibility(View.GONE);
                    zhuanxianView.setVisibility(View.GONE);
                }
                qishi = !qishi;
            }
        });

        mudiCancelAction.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mudi) {
                    mudiView.setVisibility(View.GONE);
                }else {
                    mudiView.setVisibility(View.VISIBLE);
                    zhuanxianView.setVisibility(View.GONE);
                    qishiView.setVisibility(View.GONE);
                }
                mudi = !mudi;
            }
        });



        TextView submitAction = (TextView)findViewById(R.id.kaidan_submit);
        submitAction.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Toast.makeText(KaidanActivity.this, "保存", Toast.LENGTH_SHORT).show();

            }
        });

    }

    public void getEditTextFocus() {
        fahuoName = (EditText)findViewById(R.id.kaidan_fahuo_name);
        shouhuoName = (EditText)findViewById(R.id.kaidan_shouhuo_name);
        fahuoPhone = (EditText)findViewById(R.id.kaidan_fahuo_phone);
        shouhuoPhone = (EditText)findViewById(R.id.kaidan_shouhuo_phone);
        goodsName1 = (EditText)findViewById(R.id.kaidan_goods_name_1);
        goodsName2 = (EditText)findViewById(R.id.kaidan_goods_name_2);
        goodsName3 = (EditText)findViewById(R.id.kaidan_goods_name_3);
        goodsPackage1 = (EditText)findViewById(R.id.kaidan_goods_package_1);
        goodsPackage2 = (EditText)findViewById(R.id.kaidan_goods_package_2);
        goodsPackage3 = (EditText)findViewById(R.id.kaidan_goods_package_3);

        fahuoName.setOnFocusChangeListener(new android.view.View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if (hasFocus) {
                    // 获得焦点
                    fahuoNameListView.setVisibility(View.VISIBLE);
                } else {
                    // 失去焦点
                    fahuoNameListView.setVisibility(View.GONE);
                }
            }
        });
        shouhuoName.setOnFocusChangeListener(new android.view.View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if (hasFocus) {
                    shouhuoNameListView.setVisibility(View.VISIBLE);
                } else {
                    shouhuoNameListView.setVisibility(View.GONE);
                }
            }
        });
        fahuoPhone.setOnFocusChangeListener(new android.view.View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if (hasFocus) {
                    fahuoPhoneListView.setVisibility(View.VISIBLE);
                } else {
                    fahuoPhoneListView.setVisibility(View.GONE);
                }
            }
        });
        shouhuoPhone.setOnFocusChangeListener(new android.view.View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if (hasFocus) {
                    shouhuoPhoneListView.setVisibility(View.VISIBLE);
                } else {
                    shouhuoPhoneListView.setVisibility(View.GONE);
                }
            }
        });
        goodsName1.setOnFocusChangeListener(new android.view.View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if (hasFocus) {
                    goodsName1ListView.setVisibility(View.VISIBLE);
                } else {
                    goodsName1ListView.setVisibility(View.GONE);
                }
            }
        });
        goodsName2.setOnFocusChangeListener(new android.view.View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if (hasFocus) {
                    goodsName2ListView.setVisibility(View.VISIBLE);
                } else {
                    goodsName2ListView.setVisibility(View.GONE);
                }
            }
        });
        goodsName3.setOnFocusChangeListener(new android.view.View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if (hasFocus) {
                    goodsName3ListView.setVisibility(View.VISIBLE);
                } else {
                    goodsName3ListView.setVisibility(View.GONE);
                }
            }
        });
        goodsPackage1.setOnFocusChangeListener(new android.view.View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if (hasFocus) {
                    goodsPackage1ListView.setVisibility(View.VISIBLE);
                } else {
                    goodsPackage1ListView.setVisibility(View.GONE);
                }
            }
        });
        goodsPackage2.setOnFocusChangeListener(new android.view.View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if (hasFocus) {
                    goodsPackage2ListView.setVisibility(View.VISIBLE);
                } else {
                    goodsPackage2ListView.setVisibility(View.GONE);
                }
            }
        });
        goodsPackage3.setOnFocusChangeListener(new android.view.View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if (hasFocus) {
                    goodsPackage3ListView.setVisibility(View.VISIBLE);
                } else {
                    goodsPackage3ListView.setVisibility(View.GONE);
                }
            }
        });

    }


    public void getHistoryListView() {
        fahuoNameListView = (ListView)findViewById(R.id.kaidan_fahuo_name_listview);
        fahuoPhoneListView = (ListView)findViewById(R.id.kaidan_fahuo_phone_listview);
        shouhuoNameListView = (ListView)findViewById(R.id.kaidan_shouhuo_name_listview);
        shouhuoPhoneListView = (ListView)findViewById(R.id.kaidan_shouhuo_phone_listview);
        goodsName1ListView = (ListView)findViewById(R.id.kaidan_goods_name_listview_1);
        goodsName2ListView = (ListView)findViewById(R.id.kaidan_goods_name_listview_2);
        goodsName3ListView = (ListView)findViewById(R.id.kaidan_goods_name_listview_3);
        goodsPackage1ListView = (ListView)findViewById(R.id.kaidan_goods_package_listview_1);
        goodsPackage2ListView = (ListView)findViewById(R.id.kaidan_goods_package_listview_2);
        goodsPackage3ListView = (ListView)findViewById(R.id.kaidan_goods_package_listview_3);
    }

    public void addUserInfoAction(int position) {
        switch (position) {
            case 0:
                if (sendNum == 0) {
                    LinearLayout layout = (LinearLayout)findViewById(R.id.kaidan_layout_fahuo);
                    layout.setVisibility(View.VISIBLE);
                    sendNum++;

                    shouhuoNameListView.setTranslationY(KaidanActivity.dip2px(this,41));
                    shouhuoPhoneListView.setTranslationY(KaidanActivity.dip2px(this,41));

                    goodsName1ListView.setTranslationY(KaidanActivity.dip2px(this,41));
                    goodsName2ListView.setTranslationY(KaidanActivity.dip2px(this,41));
                    goodsName3ListView.setTranslationY(KaidanActivity.dip2px(this,41));
                    goodsPackage1ListView.setTranslationY(KaidanActivity.dip2px(this,41));
                    goodsPackage2ListView.setTranslationY(KaidanActivity.dip2px(this,41));
                    goodsPackage3ListView.setTranslationY(KaidanActivity.dip2px(this,41));

                }else {
                    Toast.makeText(KaidanActivity.this, "发货地址已添加", Toast.LENGTH_SHORT).show();
                }
                break;
            case 1:
                if (receiveNum == 0) {
                    LinearLayout layout = (LinearLayout)findViewById(R.id.kaidan_layout_shouhuo);
                    layout.setVisibility(View.VISIBLE);
                    receiveNum++;

                    goodsName1ListView.setTranslationY(KaidanActivity.dip2px(this,41));
                    goodsName2ListView.setTranslationY(KaidanActivity.dip2px(this,41));
                    goodsName3ListView.setTranslationY(KaidanActivity.dip2px(this,41));
                    goodsPackage1ListView.setTranslationY(KaidanActivity.dip2px(this,41));
                    goodsPackage2ListView.setTranslationY(KaidanActivity.dip2px(this,41));
                    goodsPackage3ListView.setTranslationY(KaidanActivity.dip2px(this,41));
                }else {
                    Toast.makeText(KaidanActivity.this, "收货地址已添加", Toast.LENGTH_SHORT).show();
                }
                break;
            default:
                break;
        }


    }

    public void addGoodsInfoAction(int position) {
        switch (position) {
            case 0:
                if (addNum < 2) {
                    if (addNum == 0) {
                        LinearLayout layout1 = (LinearLayout)findViewById(R.id.kaidan_layout_goods_2);
                        layout1.setVisibility(View.VISIBLE);
                        LinearLayout layout2 = (LinearLayout)findViewById(R.id.kaidan_layout_count_2);
                        layout2.setVisibility(View.VISIBLE);
                        if (packageNum == 1) {
                            LinearLayout layout12 = (LinearLayout)findViewById(R.id.kaidan_layout_package_2);
                            layout12.setVisibility(View.VISIBLE);
                        }
                        if (weightNum == 1) {
                            LinearLayout layout12 = (LinearLayout)findViewById(R.id.kaidan_layout_weight_2);
                            layout12.setVisibility(View.VISIBLE);
                        }
                        if (volumNum == 1) {
                            LinearLayout layout12 = (LinearLayout)findViewById(R.id.kaidan_layout_volum_2);
                            layout12.setVisibility(View.VISIBLE);
                        }



                    }else {
                        LinearLayout layout1 = (LinearLayout)findViewById(R.id.kaidan_layout_goods_2);
                        layout1.setVisibility(View.VISIBLE);
                        LinearLayout layout2 = (LinearLayout)findViewById(R.id.kaidan_layout_count_2);
                        layout2.setVisibility(View.VISIBLE);
                        LinearLayout layout3 = (LinearLayout)findViewById(R.id.kaidan_layout_goods_3);
                        layout3.setVisibility(View.VISIBLE);
                        LinearLayout layout4 = (LinearLayout)findViewById(R.id.kaidan_layout_count_3);
                        layout4.setVisibility(View.VISIBLE);
                        if (packageNum == 1) {
                            LinearLayout layout12 = (LinearLayout)findViewById(R.id.kaidan_layout_package_2);
                            layout12.setVisibility(View.VISIBLE);
                            LinearLayout layout13 = (LinearLayout)findViewById(R.id.kaidan_layout_package_3);
                            layout13.setVisibility(View.VISIBLE);
                        }
                        if (weightNum == 1) {
                            LinearLayout layout12 = (LinearLayout)findViewById(R.id.kaidan_layout_weight_2);
                            layout12.setVisibility(View.VISIBLE);
                            LinearLayout layout13 = (LinearLayout)findViewById(R.id.kaidan_layout_weight_3);
                            layout13.setVisibility(View.VISIBLE);
                        }
                        if (volumNum == 1) {
                            LinearLayout layout12 = (LinearLayout)findViewById(R.id.kaidan_layout_volum_2);
                            layout12.setVisibility(View.VISIBLE);
                            LinearLayout layout13 = (LinearLayout)findViewById(R.id.kaidan_layout_volum_3);
                            layout13.setVisibility(View.VISIBLE);
                        }


                    }
                    addNum++;
                }else {
                    Toast.makeText(KaidanActivity.this, "货物最多三条", Toast.LENGTH_SHORT).show();
                }
                break;
            case 1:
                if (packageNum < 1) {
                    if (addNum == 0) {
                        LinearLayout layout1 = (LinearLayout)findViewById(R.id.kaidan_layout_package_1);
                        layout1.setVisibility(View.VISIBLE);
                    }
                    if (addNum == 1) {
                        LinearLayout layout1 = (LinearLayout)findViewById(R.id.kaidan_layout_package_1);
                        layout1.setVisibility(View.VISIBLE);
                        LinearLayout layout2 = (LinearLayout)findViewById(R.id.kaidan_layout_package_2);
                        layout2.setVisibility(View.VISIBLE);
                    }
                    if (addNum == 2) {
                        LinearLayout layout1 = (LinearLayout)findViewById(R.id.kaidan_layout_package_1);
                        layout1.setVisibility(View.VISIBLE);
                        LinearLayout layout2 = (LinearLayout)findViewById(R.id.kaidan_layout_package_2);
                        layout2.setVisibility(View.VISIBLE);
                        LinearLayout layout3 = (LinearLayout)findViewById(R.id.kaidan_layout_package_3);
                        layout3.setVisibility(View.VISIBLE);
                    }
                    packageNum++;
                }else {
                    Toast.makeText(KaidanActivity.this, "包装已添加", Toast.LENGTH_SHORT).show();
                }
                break;
            case 2:
                if (weightNum < 1) {
                    if (addNum == 0) {
                        LinearLayout layout1 = (LinearLayout)findViewById(R.id.kaidan_layout_weight_1);
                        layout1.setVisibility(View.VISIBLE);
                    }
                    if (addNum == 1) {
                        LinearLayout layout1 = (LinearLayout)findViewById(R.id.kaidan_layout_weight_1);
                        layout1.setVisibility(View.VISIBLE);
                        LinearLayout layout2 = (LinearLayout)findViewById(R.id.kaidan_layout_weight_2);
                        layout2.setVisibility(View.VISIBLE);
                    }
                    if (addNum == 2) {
                        LinearLayout layout1 = (LinearLayout)findViewById(R.id.kaidan_layout_weight_1);
                        layout1.setVisibility(View.VISIBLE);
                        LinearLayout layout2 = (LinearLayout)findViewById(R.id.kaidan_layout_weight_2);
                        layout2.setVisibility(View.VISIBLE);
                        LinearLayout layout3 = (LinearLayout)findViewById(R.id.kaidan_layout_weight_3);
                        layout3.setVisibility(View.VISIBLE);
                    }
                    weightNum++;
                }else {
                    Toast.makeText(KaidanActivity.this, "重量已添加", Toast.LENGTH_SHORT).show();
                }
                break;
            case 3:
                if (volumNum < 1) {
                    if (addNum == 0) {
                        LinearLayout layout1 = (LinearLayout)findViewById(R.id.kaidan_layout_volum_1);
                        layout1.setVisibility(View.VISIBLE);
                    }
                    if (addNum == 1) {
                        LinearLayout layout1 = (LinearLayout)findViewById(R.id.kaidan_layout_volum_1);
                        layout1.setVisibility(View.VISIBLE);
                        LinearLayout layout2 = (LinearLayout)findViewById(R.id.kaidan_layout_volum_2);
                        layout2.setVisibility(View.VISIBLE);
                    }
                    if (addNum == 2) {
                        LinearLayout layout1 = (LinearLayout)findViewById(R.id.kaidan_layout_volum_1);
                        layout1.setVisibility(View.VISIBLE);
                        LinearLayout layout2 = (LinearLayout)findViewById(R.id.kaidan_layout_volum_2);
                        layout2.setVisibility(View.VISIBLE);
                        LinearLayout layout3 = (LinearLayout)findViewById(R.id.kaidan_layout_volum_3);
                        layout3.setVisibility(View.VISIBLE);
                    }
                    volumNum++;
                }else {
                    Toast.makeText(KaidanActivity.this, "体积已添加", Toast.LENGTH_SHORT).show();
                }
                break;
            default:
                break;
        }
        RelativeLayout.LayoutParams paramTest1 = (RelativeLayout.LayoutParams) goodsName2ListView.getLayoutParams();
        paramTest1.topMargin = dip2px(this,41*(packageNum+weightNum+volumNum+2)+340);
        goodsName2ListView.setLayoutParams(paramTest1);

        RelativeLayout.LayoutParams paramTest2 = (RelativeLayout.LayoutParams) goodsName3ListView.getLayoutParams();
        paramTest2.topMargin = dip2px(this,41 * (packageNum+weightNum+volumNum+2) * 2+340);
        goodsName3ListView.setLayoutParams(paramTest2);

        RelativeLayout.LayoutParams paramTest3 = (RelativeLayout.LayoutParams) goodsPackage1ListView.getLayoutParams();
        paramTest3.topMargin = dip2px(this,41 * 2 +340);
        goodsPackage1ListView.setLayoutParams(paramTest3);

        RelativeLayout.LayoutParams paramTest4 = (RelativeLayout.LayoutParams) goodsPackage2ListView.getLayoutParams();
        paramTest4.topMargin = dip2px(this,41 * (packageNum+weightNum+volumNum+2) + 41 * 2 +340);
        goodsPackage2ListView.setLayoutParams(paramTest4);

        RelativeLayout.LayoutParams paramTest5 = (RelativeLayout.LayoutParams) goodsPackage3ListView.getLayoutParams();
        paramTest5.topMargin = dip2px(this,41 * (packageNum+weightNum+volumNum+2 ) * 2 + 41 * 2+340);
        goodsPackage3ListView.setLayoutParams(paramTest5);

    }

    public void addServiceAction(int position) {
        switch (position) {
            case 0:
                if (huowujiazhi == 0) {
                    LinearLayout layout = (LinearLayout)findViewById(R.id.kaidan_layout_service_1);
                    layout.setVisibility(View.VISIBLE);
                    huowujiazhi++;
                }else {
                    Toast.makeText(KaidanActivity.this, "货物价值已添加", Toast.LENGTH_SHORT).show();
                }
                break;
            case 1:
                if (baoxianjine == 0) {
                    LinearLayout layout = (LinearLayout)findViewById(R.id.kaidan_layout_service_2);
                    layout.setVisibility(View.VISIBLE);
                    baoxianjine++;
                }else {
                    Toast.makeText(KaidanActivity.this, "保险金额已添加", Toast.LENGTH_SHORT).show();
                }
                break;
            default:
                break;
        }

    }


    public void addCostAction(int position) {
        switch (position) {
            case 0:
                if (daofu == 0) {
                    LinearLayout layout = (LinearLayout)findViewById(R.id.kaidan_layout_cost_1);
                    layout.setVisibility(View.VISIBLE);
                    daofu++;
                }else {
                    Toast.makeText(KaidanActivity.this, "到付已添加", Toast.LENGTH_SHORT).show();
                }
                break;
            case 1:
                if (fankuan == 0) {
                    LinearLayout layout = (LinearLayout)findViewById(R.id.kaidan_layout_cost_2);
                    layout.setVisibility(View.VISIBLE);
                    fankuan++;
                }else {
                    Toast.makeText(KaidanActivity.this, "返款已添加", Toast.LENGTH_SHORT).show();
                }
                break;
            case 2:
                if (qianfan == 0) {
                    LinearLayout layout = (LinearLayout)findViewById(R.id.kaidan_layout_cost_3);
                    layout.setVisibility(View.VISIBLE);
                    qianfan++;
                }else {
                    Toast.makeText(KaidanActivity.this, "欠返已添加", Toast.LENGTH_SHORT).show();
                }
                break;
            case 3:
                if (huidanfenshu == 0) {
                    LinearLayout layout = (LinearLayout)findViewById(R.id.kaidan_layout_cost_4);
                    layout.setVisibility(View.VISIBLE);
                    huidanfenshu++;
                }else {
                    Toast.makeText(KaidanActivity.this, "回单份数已添加", Toast.LENGTH_SHORT).show();
                }
                break;
            case 4:
                if (huidanfu == 0) {
                    LinearLayout layout = (LinearLayout)findViewById(R.id.kaidan_layout_cost_5);
                    layout.setVisibility(View.VISIBLE);
                    huidanfu++;
                }else {
                    Toast.makeText(KaidanActivity.this, "回单付已添加", Toast.LENGTH_SHORT).show();
                }
                break;
            case 5:
                if (beizhu == 0) {
                    LinearLayout layout = (LinearLayout)findViewById(R.id.kaidan_layout_cost_6);
                    layout.setVisibility(View.VISIBLE);
                    beizhu++;
                }else {
                    Toast.makeText(KaidanActivity.this, "备注已添加", Toast.LENGTH_SHORT).show();
                }
                break;
            default:
                break;
        }
    }

    public static int dip2px(Context context, float dpValue) {
        final float scale = context.getResources().getDisplayMetrics().density;
        return (int) (dpValue * scale + 0.5f);
    }

    public void backAction(){
        TextView textView = (TextView)findViewById(R.id.kaidan_back);
        textView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }
}
